package com.seagull.sb.service;

import java.util.List;

import javax.annotation.security.RolesAllowed;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.SecurityContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.seagull.sb.bo.HomeWorkBO;
import com.seagull.sb.domain.HomeWork;
import com.seagull.sb.domain.Student;
import com.seagull.sb.dto.HomeWorkDto;
import com.seagull.sb.util.SBRequestContext;
import com.seagull.sb.util.ServiceMapper;

@Component
@Path("/homework")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class HomeWorkService extends BaseService {

	@Autowired 
	HomeWorkBO homeWorkBO;
	
	private ServiceMapper sm = ServiceMapper.getInstaMapper();

	@GET
	@Path("/")
	@RolesAllowed({"teacher","student"})
	public List<HomeWorkDto> getHomework(@Context SecurityContext sc) {
		SBRequestContext rc = populateRequestContext(sc); 
		List<HomeWork> homeWork = homeWorkBO.getHomeWork(rc);
		return sm.mapToHomeWorkDto(homeWork);
	}
	
	@POST
	@Path("/")
	@RolesAllowed({"teacher"})
	public HomeWorkDto saveHomeWork(@Context SecurityContext sc, 
			HomeWorkDto homeWorkDto) {
		SBRequestContext rc = populateRequestContext(sc);
		HomeWork homeWork = sm.mapToHomeWork(homeWorkDto);
		homeWorkBO.saveHomeWork(rc, homeWork);
		
		System.out.println("saveHomeWork - Successful.");
		return null;
 	}	
//	
//	@GET
//	@Path("/view/{classid}")
//	@RolesAllowed({"teacher"})
//	public List<NoticeDto> getNoticeByClass(@Context SecurityContext sc,
//			@PathParam("classid") int classid) {
//		SBRequestContext rc = populateRequestContext(sc); 
//		List<Notice> notices = noticeBO.getNotice(rc,new NoticeDto());
//		return sm.mapToNoticeDto(notices);
//
//	}
//	
//	@GET
//	@Path("/view/{noticeid}")
//	@RolesAllowed({"student","teacher"})
//	public List<NoticeDto> viewNotice(@Context SecurityContext sc, 
//			@PathParam("noticeid") int noticeid) {
//		SBRequestContext rc = populateRequestContext(sc); 
//
//		NoticeDto noticeDto  = new NoticeDto();
//		noticeDto.setId(noticeid);
//
//		List<Notice> notices = noticeBO.viewedNotice(rc,noticeDto);
//		return sm.mapToNoticeDto(notices);
//
//	}
// 
//	@POST
//	@Path("/")
//	public NoticeDto saveNotice(@Context SecurityContext sc, 
//			NoticeDto noticeDto) {
//		SBRequestContext rc = new SBRequestContext();
//		Notice notice = sm.mapToNotice(noticeDto);
//		noticeBO.saveNotice(rc, notice);
//		System.out.println("saveNotice - Successful.");
//		return noticeDto;
// 	}
}